home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 February / OpenLinux 2.3 CD.iso / live / usr / share / vim / syntax / xpm.vim < prev    next >
Encoding:
Text File  |  1999-08-10  |  3.8 KB  |  128 lines

  1. " Vim syntax file
  2. " Language:    X Pixmap
  3. " Maintainer:    Ronald Schild <rs@dps.de>
  4. " Last change:    1998 August 19
  5.  
  6. " Remove any old syntax stuff hanging around
  7. syn clear
  8.  
  9. syn keyword xpmType        char
  10. syn keyword xpmStorageClass    static
  11. syn keyword xpmTodo        TODO FIXME XXX  contained
  12. syn region  xpmComment        start="/\*"  end="\*/"  contains=xpmTodo
  13. syn region  xpmPixelString    start=+"+  skip=+\\\\\|\\"+  end=+"+  contains=@xpmColors
  14.  
  15. if has("gui_running")
  16.  
  17. let color  = ""
  18. let chars  = ""
  19. let colors = 0
  20. let cpp    = 0
  21. let n      = 0
  22. let i      = 1
  23.  
  24. while i <= line("$")        " scanning all lines
  25.  
  26.    let s = matchstr(getline(i), '".\{-1,}"')
  27.    if s != ""            " does line contain a string?
  28.  
  29.       if n == 0            " first string is the Values string
  30.  
  31.      " get the 3rd value: colors = number of colors
  32.      let colors = substitute(s, '"\s*\d\+\s\+\d\+\s\+\(\d\+\).*"', '\1', '')
  33.      " get the 4th value: cpp = number of character per pixel
  34.      let cpp = substitute(s, '"\s*\d\+\s\+\d\+\s\+\d\+\s\+\(\d\+\).*"', '\1', '')
  35.  
  36.      " highlight the Values string as normal string (no pixel string)
  37.      exe 'syn match xpmValues /'.s.'/'
  38.      hi link xpmValues String
  39.  
  40.      let n = 1        " n = color index
  41.  
  42.       elseif n <= colors    " string is a color specification
  43.  
  44.      " get chars = <cpp> length string representing the pixels
  45.      " (first incl. the following whitespace)
  46.      let chars = substitute(s, '"\(.\{'.cpp.'}\s\).*"', '\1', '')
  47.  
  48.      " now get color, first try 'c' key if any (color visual)
  49.      let color = substitute(s, '".*\sc\s\+\(.\{-}\)\s*\(\(g4\=\|[ms]\)\s.*\)*\s*"', '\1', '')
  50.      if color == s
  51.         " no 'c' key, try 'g' key (grayscale with more than 4 levels)
  52.         let color = substitute(s, '".*\sg\s\+\(.\{-}\)\s*\(\(g4\|[ms]\)\s.*\)*\s*"', '\1', '')
  53.         if color == s
  54.            " next try: 'g4' key (4-level grayscale)
  55.            let color = substitute(s, '".*\sg4\s\+\(.\{-}\)\s*\([ms]\s.*\)*\s*"', '\1', '')
  56.            if color == s
  57.           " finally try 'm' key (mono visual)
  58.           let color = substitute(s, '".*\sm\s\+\(.\{-}\)\s*\(s\s.*\)*\s*"', '\1', '')
  59.           if color == s
  60.              let color = ""
  61.           endif
  62.            endif
  63.         endif
  64.      endif
  65.  
  66.      " Vim cannot handle RGB codes with more than 6 hex digits
  67.      if color =~ '#\x\{7,}$'
  68.         let color = substitute(color, '\(\x\x\)\x\x', '\1', 'g')
  69.      endif
  70.  
  71.      " nor with 3 digits
  72.      if color =~ '#\x\{3}$'
  73.         let color = substitute(color, '\(\x\)\(\x\)\(\x\)', '0\10\20\3', '')
  74.      endif
  75.  
  76.      " escape meta characters in patterns
  77.      let s = escape(s, '\*^$.~[]')
  78.      let chars = escape(chars, '\*^$.~[]')
  79.  
  80.      " now create syntax items
  81.      " highlight the color string as normal string (no pixel string)
  82.      exe 'syn match xpmCol'.n.'Def /'.s.'/ contains=xpmCol'.n.'inDef'
  83.      exe 'hi link xpmCol'.n.'Def String'
  84.  
  85.      " but highlight the first whitespace after chars in its color
  86.      exe 'syn match xpmCol'.n.'inDef /"'.chars.'/hs=s+'.(cpp+1).' contained'
  87.      exe 'hi link xpmCol'.n.'inDef xpmColor'.n
  88.  
  89.      " remove the following whitespace from chars
  90.      let chars = substitute(chars, '.$', '', '')
  91.  
  92.      " and create the syntax item contained in the pixel strings
  93.      exe 'syn match xpmColor'.n.' /'.chars.'/ contained'
  94.      exe 'syn cluster xpmColors add=xpmColor'.n
  95.  
  96.      " if no color or color = "None" show background
  97.      if color == ""  ||  substitute(color, '.*', '\L&', '') == 'none'
  98.         exe 'hi xpmColor'.n.' guifg=bg'
  99.         exe 'hi xpmColor'.n.' guibg=NONE'
  100.      else
  101.         exe 'hi xpmColor'.n." guifg='".color."'"
  102.         exe 'hi xpmColor'.n." guibg='".color."'"
  103.      endif
  104.      let n = n + 1
  105.       else
  106.      break        " no more color string
  107.       endif
  108.    endif
  109.    let i = i + 1
  110. endwhile
  111.  
  112. unlet color chars colors cpp n i s
  113.  
  114. endif        " has("gui_running")
  115.  
  116. if !exists("did_xpm_syntax_inits")
  117.    let did_xpm_syntax_inits = 1
  118.    hi link xpmType        Type
  119.    hi link xpmStorageClass    StorageClass
  120.    hi link xpmTodo        Todo
  121.    hi link xpmComment        Comment
  122.    hi link xpmPixelString    String
  123. endif
  124.  
  125. let b:current_syntax = "xpm"
  126.  
  127. " vim: ts=8:sw=3:noet:
  128.